// api/dingtalk.js
export default async function handler(req, res) {
  if (req.method !== 'POST') {
    return res.status(405).json({ error: 'Method Not Allowed' });
  }
  const { content } = req.body;
  const webhook = 'https://oapi.dingtalk.com/robot/send?access_token=186933f788400a06f3ebb820888c0504e1d0da283fff22d99a389ca829615938'; // 填你的真实Webhook
  const safeContent = '[设备] ' + content;
  try {
    const dingRes = await fetch(webhook, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        msgtype: 'text',
        text: { content: safeContent }
      })
    });
    const data = await dingRes.json();
    res.status(200).json(data);
  } catch (e) {
    res.status(500).json({ error: e.message });
  }
}
